package core.category.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import core.cms.model.Block;
import core.product.model.Product;

@Entity
@Table(name="category")
public class Category implements Serializable
{

	private static final long serialVersionUID = 131323L;
	private Long uuid;
	private String name ;
	private int depth ;
	private String path ;
	private Category parent ;
	private CategoryType categoryType ;
	private Set<Product> products ;
	private Block block;
	
	@Id
	@GeneratedValue
	@Column(name="uuid")
	public Long getUuid() {
		return uuid;
	}
	
	public void setUuid(Long uuid) {
		this.uuid = uuid;
	}
	
	@Column(name="name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name="depth")
	public int getDepth() {
		return depth;
	}

	public void setDepth(int depth) {
		this.depth = depth;
	}
	@Column(name="path")
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	@ManyToOne(cascade = CascadeType.ALL)
	public CategoryType getCategoryType() {
		return categoryType;
	}

	public void setCategoryType(CategoryType categoryType) {
		this.categoryType = categoryType;
	}
	@ManyToMany(cascade = CascadeType.ALL , fetch = FetchType.EAGER)
	@JoinTable(name = "category_product", joinColumns = {@JoinColumn(name ="category_uuid") }, inverseJoinColumns = {@JoinColumn(name="product_uuid")})
	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}
	@ManyToOne(cascade = CascadeType.ALL)
	public Category getParent() {
		return parent;
	}

	public void setParent(Category parent) {
		this.parent = parent;
	}
	
	@ManyToOne(cascade = CascadeType.ALL)
	public Block getBlock() {
		return block;
	}

	public void setBlock(Block block) {
		this.block = block;
	}
}
